//package com.all.learning.guava.concurrent.domain;
//
//import java.io.File;
//import java.io.FileNotFoundException;
//import java.io.IOException;
//
//import com.google.common.io.BaseEncoding;
//import com.google.common.io.Files;
////import com.google.common.util.concurrent.FutureFallback;
//import com.google.common.util.concurrent.ListenableFuture;
//import com.google.common.util.concurrent.SettableFuture;
//
//public class FutureFallbackImpl implements FutureFallback<String> {
//
//	@Override
//	public ListenableFuture<String> create(Throwable t) throws Exception {
//		if (t instanceof FileNotFoundException) {
//			SettableFuture<String> settableFuture = SettableFuture.create();
//			settableFuture.set("Not Found");
//			return settableFuture;
//		}
//		throw new Exception(t);
//	}
//
//	public static void main(String[] args) throws Exception {
//		File file = new File("srcfile.txt");
//		byte[] bytes = Files.toByteArray(file);
//		BaseEncoding baseEncoding = BaseEncoding.base64();
//		String encoded = baseEncoding.encode(bytes); // 将字节以Base64编码
//		// 异步转换：
//		// ListenableFuture<Person> lf = Futures.transform(ListenableFuture<String> f,AsyncFunction<String,Person> af);
//
//		// ListenableFuture<String> lf = Futures.withFallback(ListenableFuture<String> f,FutureFallback<String> fb);
//
//
////		File srcFile = new File("srcfile.txt");
////	    File encodedFile = new File("encodedfile.txt");
////	    CharSink charSink = Files.asCharSink(encodedFile, Charsets.UTF_8);
////	    BaseEncoding baseEncoding = BaseEncoding.base64();
////	    ByteSink byteSink = baseEncoding.encodingSink(charSink); //将charSink转为ByteSink
////	    ByteSource byteSource = Files.asByteSource(srcFile);
////	    byteSource.copyTo(byteSink); //copy ByteSource to ByteSink
////	    String encodedBytes = baseEncoding.encode(byteSource.read());
//	}
//
//}
